#ifndef DEBUG_H
#define DEBUG_H

#include <stdio.h>

#define DEBUG_ERR  0
#define DEBUG_WARN 1
#define DEBUG_INFO 2
#define DEBUG_VERB 3
#define DEBUG_DBG  4

extern unsigned int debug_level;


#define debug( level, fmt, args... )                                          \
  do {                                                                        \
    if ( debug_level >= level )                                               \
      fprintf( stderr, fmt, ##args );                                         \
  } while (0)

#define err( fmt, args... )     debug( DEBUG_ERR,  "ERR: "  fmt, ##args )
#define warn( fmt, args... )    debug( DEBUG_WARN, "WARN: " fmt, ##args )
#define info( fmt, args... )    debug( DEBUG_INFO, "INFO: " fmt, ##args )
#define verbose( fmt, args... ) debug( DEBUG_VERB, "VERB: " fmt, ##args )
#define dbg( fmt, args... )                                                   \
  debug( DEBUG_DBG, "%s:%d:%s: " fmt, __FILE__, __LINE__, __FUNCTION__,       \
         ##args )


#endif /* DEBUG_H */
